package com.mm.common.utils;


import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * @BelongsProject: 0.forum_system
 * @BelongsPackage: com.example.forum_system.common
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-11-06  16:19
 * @Version : 1.0
 * @Description : TODO
 */
public class MD5Util {

    public static String md5(String src){
        return DigestUtils.md5DigestAsHex(src.getBytes(StandardCharsets.UTF_8));
    }

    public static String md5Salt(String src,String salt){
        return salt+"$"+md5(salt+src);
    }

    public static boolean verifyPassword(String password,String md5Password){
        String salt = md5Password.split("\\$")[0];
        if(md5Password.equals(md5Salt(password,salt))){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(md5Salt("2239473866Qq",UUIDUtil.UUID_32()));
    }

    
}
